<?php


namespace app\api\controller\uniapp;


use app\api\model\ShopYiwu;
use app\api\model\Users;
use app\common\controller\Api;
use app\api\controller\Wxutils;
use app\api\model\Region;
use think\Config;
use think\Db;

/**
 * 小程序首页接口
 * Class Index
 * @package app\api\controller\uniapp
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $service = null;

    public function _initialize()
    {
        parent::_initialize();
        $version = str_replace(".","",$this->version);
        $className = basename(__CLASS__);
        $serviceName = "app\\api\\service\\uniapp\\index\\Index{$version}";
        $this->service = new $serviceName;
    }

    public function index(){
        return $this->service->load_list();
    }
    public function load_ads(){
        return $this->service->load_ads();
    }
    public function load_city(){
        $group = Region::where('level',1)->group('index')->order('index')->select();
        foreach ($group as $k=>$v){
            $province = Region::where('index',$v['index'])->select();
            foreach ($province as $k1=>$v1){
                $city = Region::where('parent_id',$v1['id'])->where('CHAR_LENGTH(name) > 1')->select();
                $province[$k1]['data'] = $city;
            }
            $group[$k]['data'] = $province;
        }
        $this->success('加载成功',$group);
    }
    public function search(){
        return $this->service->search();
    }
}